/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bean;

/**
 *
 * @author Jeferson
 */

import com.google.appengine.api.urlfetch.HTTPRequest;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServletRequest;
import src.bd.PMF;
import src.bd.Reclamacoes;
public class ReclamacoesBean {
    public ReclamacoesBean() {

    }

    public void salva(String nomePolitico, String prometido){
        Reclamacoes re = new Reclamacoes(nomePolitico, prometido);

        PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(re);
        } finally {
            pm.close();
        }
    }

    public void salva(HttpServletRequest r){
        salva(r.getParameter("nomePolitico"), r.getParameter("prometido"));
    }

    public List<Reclamacoes> lista(){

        PersistenceManager pm = PMF.get().getPersistenceManager();
        String query = "select from " + Reclamacoes.class.getName() + " order by data desc ";
        List<Reclamacoes> reclamacoes = (List<Reclamacoes>) pm.newQuery(query).execute();
        return reclamacoes;
    }

    public void deleteAll(){
        System.out.println("ddd");
        PersistenceManager pm = PMF.get().getPersistenceManager();
        String query = "select from " + Reclamacoes.class.getName() + " order by data desc ";
        List<Reclamacoes> lista = (List<Reclamacoes>) pm.newQuery(query).execute();
        for(Reclamacoes re : lista){
            pm.deletePersistentAll(re);
        }
    }

}
